package com.fun.feifun.base.auth;

import cn.dev33.satoken.oauth2.logic.SaOAuth2Template;
import cn.dev33.satoken.oauth2.model.SaClientModel;
import org.springframework.stereotype.Component;

/**
 * @Author: wukefei
 * @Date: Created in 2022/4/24 21:39
 * @Description:
 * @Version: 1.0
 *
 */
@Component
public class SaOAuth2TemplateImpl extends SaOAuth2Template {

	// 根据 id 获取 Client 信息
	@Override
	public SaClientModel getClientModel(String clientId) {
		//这里可以重 数据库中获取
		//授权中心
		if(BaseConstant.auth_modular_client_id.equals(clientId)) {
			return new SaClientModel()
					.setClientId(BaseConstant.auth_modular_client_id)
					.setClientSecret(BaseConstant.auth_modular_client_secret)
					.setAllowUrl("*")
					.setContractScope(BaseConstant.auth_modular_contract_scope)
					.setIsAutoMode(true);
		}
		//博客系统
		if(BaseConstant.auth_modular_client_id.equals(clientId)) {
			return new SaClientModel()
					.setClientId(BaseConstant.blog_modular_client_id)
					.setClientSecret(BaseConstant.blog_modular_client_secret)
					.setAllowUrl("*")
					.setContractScope(BaseConstant.blog_modular_contract_scope)
					.setIsAutoMode(true);
		}

		return null;
	}

	// 根据ClientId 和 LoginId 获取openid
	@Override
	public String getOpenid(String clientId, Object loginId) {
		// 此为模拟数据，真实环境需要从数据库查询
		return "gr_SwoIN0MC1ewxHX_vfCW3BothWDZMMtx__";
	}
}
